<title>店铺管理</title>
<style>
    /**/
    .layui-table th, .layui-table td,.layui-table-cell{
        line-height: 100px;height: 100px;
    }
    td .laytable-cell-1-0-3{
        line-height: 30px;
    }
</style>


<div class="layui-card layadmin-header" style="height: 50px; line-height: 50px;">
	<div class="layui-breadcrumb" lay-filter="breadcrumb" style="padding: 0 15px;">
		<a lay-href="">商家中心</a>
		<a><cite>店铺管理</cite></a>
	</div>
</div>

<div class="layui-fluid">
	<div class="layui-card">

		<div class="layui-card-body">
			<div style="padding-bottom: 10px;">
				<button class="layui-btn layuiadmin-btn-admin">添加</button>
			</div>

			<table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>
			<script type="text/html" id="buttonTpl">
				{{#  if(d.status == 1){ }}
				<button class="layui-btn layui-btn-xs">已审核</button>
				{{#  } else if(d.status == 2) { }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">未通过</button>
				{{#  } else { }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
				{{#  } }}
			</script>
			<script type="text/html" id="table-useradmin-admin">
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			</script>
		</div>
	</div>
</div>

<script type="text/html" id="imgTpl">
	<img src="{{d.img}}" style="width:50px;height: 50px;"/>
	<br/>
	<a href="{{d.url}}" target="_blank">查看店铺</a>
</script>





<script>
	layui.contr1='store';
	layui.define(['table', 'form'], function(exports){
		var $ = layui.$
			,admin = layui.admin
			,view = layui.view
			,table = layui.table
			,form = layui.form
			,util = layui.util;

		//列表
		table.render({
			elem: '#LAY-user-back-manage'
			,url: './'+layui.contr1+'/list' //`id`,  `mall_name`, `gapday`, `name`, `url`, `img`, `status`
			//,editTrigger: 'dblclick' // 触发编辑的事件类型（默认 click ）。 v2.7.0 新增，之前版本固定为单击触发
			,cols: [[
				//{type: 'checkbox', fixed: 'left'},
				{field: 'id', width: 80, title: 'ID'}
				,{field: 'mall_name', title: '平台'}
				,{field: 'name', title: '店铺名称'}
				,{field: 'img', title: '店铺截图', templet: '#imgTpl'}
				,{field: 'gapday', title: '控制接单间隔(天)'}
				,{field: 'status', title: '审核状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
				,{title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
			]]
			,text: '对不起，加载出现异常！'
			,page: false
			,limit: 30
			,height: 'full-320'
		});

		//工具条
		table.on('tool(LAY-user-back-manage)', function(obj){
			var data = obj.data;
			if(obj.event === 'edit'){
				admin.popup({
					title: '编辑店铺'
					,area: ['420px', '450px']
					,id: 'LAY-popup-user-add'
					,success: function(layero, index){
						view(this.id).render(layui.contr1+'/info', data).done(function(){
							form.render(null, 'layuiadmin-form-admin');

							//提交
							form.on('submit(LAY-user-back-submit)', function(data){

								//提交 Ajax 成功后，关闭当前弹层并重载表格
								admin.req({
									url: './'+layui.contr1+'/edit'
									,type: 'post'
									,data: data.field
									,done: function(res){
										layui.table.reload('LAY-user-back-manage'); //重载表格
										layer.close(index); //执行关闭
									}
								});

							});

						});
					}
				});
			}
		});


		$('.layui-btn.layuiadmin-btn-admin').on('click',function(){
			admin.popup({
				title: '添加店铺'
				,area: ['420px', '500px']
				,id: 'LAY-popup-useradmin-add'
				,success: function(layero, index){
					view(this.id).render(layui.contr1+'/info',{'status':true}).done(function(){
						form.render(null, 'layuiadmin-form-admin');
						//提交
						form.on('submit(LAY-user-back-submit)', function(data){
							admin.req({
								url: './'+layui.contr1+'/add'
								,type: 'post'
								,data: data.field
								,done: function(res){
									layui.table.reload('LAY-user-back-manage'); //重载表格
									layer.close(index); //执行关闭
								}
							});

						});
					});
				}
			});
		});


	});
</script>


